﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PDKUserInfo : MonoBehaviour {

    public UISprite avatar;
    public UILabel userNameLable;
    public UILabel userID;
    public UILabel userCoin;
    public UITexture wxAvatar;

    public GameObject CloseBtn;
    private void Awake()
    {
        UIEventListener.Get(CloseBtn).onClick = ButtonClick;
    }

    void ButtonClick(GameObject button)
    {
        if (button.name == "CloseBtn")
        {
            Destroy(gameObject);
        }
    }

    public void LoadUserInfo(int seatid)
    {
        EginUser user = EginUser.Instance;        
        for (int i = 0; i < user.gameUserInfoList.Count; i++)
        {
            if (user.gameUserInfoList[i].SeatId == seatid)
            {
                if(user.gameUserInfoList[i].AvatarUrl != ""){
                    WXAvatarManager._instance.GetWxAvatar(user.gameUserInfoList[i].Uid,wxAvatar,user.gameUserInfoList[i].AvatarUrl);
                    wxAvatar.gameObject.SetActive(true);
                }
                avatar.spriteName = user.gameUserInfoList[i].AvatarId.ToString();
                userNameLable.text = "昵称：" + user.gameUserInfoList[i].Nickname;
                userID.text = "ID：" + user.gameUserInfoList[i].Uid.ToString();
                int coin = 0;
                if (user.ControlScene == 1 && EginPDK.Instance.isCardRoom == false)
                {
                    coin = user.gameUserInfoList[i].Score;
                }               
                else
                {
                    coin = user.gameUserInfoList[i].BagCoinCount;
                }
                //string tempStr = "";
                //if (Mathf.Abs(coin) <= 10000)
                //{
                //    tempStr = (Mathf.Abs(coin)).ToString();
                //}
                //else if (Mathf.Abs(coin) > 10000)
                //{
                //    int tempScore = Mathf.Abs(coin);
                //    tempStr = tempScore / 10000 + ((((float)(tempScore % 10000) / (float)10000)).ToString("0.0")).Remove(0, 1) + "W";
                //}
                userCoin.text = user.ReturnMoney(coin);                
            }
        }

    }
}
